#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
//把一个数组的奇数放前面，偶数放后面
void exchange(int* arr, int n)
{
	int left = 0;
	int right = n - 1;
	while (left < right)
	{
		//从前往后找偶数
		while ((left < right) && (arr[left] % 2 == 1))//找到奇数那就往后找，找到偶数就跳出循环
		{
			left++;
		}
		//从后往前找奇数
		while ((left < right) && (arr[right] % 2 == 0))//找到偶数那就往前找，找到奇数就跳出循环
		{
			right--;
		}
		if (left < right)
		{
			int temp = arr[left];
			arr[left] = arr[right];
			arr[right] = temp;
		}
	}
}
int main()
{
	int arr[] = {1,2,3,4,5,6,7,8,9,10};
	int sz = sizeof(arr) / sizeof(arr[0]);
	exchange(arr, sz);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}